Re: Converting comma-delimited data to tab-delimited

Поиск
Список
Период
Сортировка
От Randall Perry
Тема Re: Converting comma-delimited data to tab-delimited
Дата
Msg-id 20020331202434.JRAL27903.imf24bis.bellsouth.net@[216.77.205.40]
обсуждение исходный текст
Ответ на Re: Converting comma-delimited data to tab-delimited  (Randall Perry <rgp@systame.com>)
Список pgsql-general
Just discovered the following code only works if there's only ONE comma
between quotes. Back to the drawing board :(

> I answered my question by writing the following perl script:
>
>
> #!/usr/local/bin/perl
> # comma_to_tab.pl
> #
> # usage: ./comma_to_tab.pl data.csv > data.tab
> #
> # Description:
> #    1. finds any occurences of a comma between double quotes and replaces
> it with low ASCII char x00
> #    2. replaces all remaining commas with tabs
> #    3. changes all x00 chars back to commas
>
> while (<>) {
>   s/\"(.*)(,)(.*)\"/$1\x00$3/g;
>   s/,/\t/g;
>   s/\x00/,/g;
>   print $_;
> }
>
>
>> perl -ne 's/^ *"//; s/" *$//; print join("\t", split(/\" *, *\"/))'
>> your-table.csv > your-table.tab

--
Randy Perry
sysTame
Mac Consulting/Sales

phn                 561.589.6449
mobile email        help@systame.com



В списке pgsql-general по дате отправления:

Предыдущее
От: Frank Finner
Дата:
Сообщение: Re: Converting comma-delimited data to tab-delimited
Следующее
От: Randall Perry
Дата:
Сообщение: Re: Converting comma-delimited data to tab-delimited